﻿using System;

namespace BiggerThanNeighbors
{
    class BiggerThanNeighbors
    {
        static bool IsValidIndex(int[] array, int index)
        {
            return index < array.Length && 0 <= index;
        }

        static bool IsBiggerThanNeighbors(int[] array, int index)
        {
            if (!IsValidIndex(array, index))
            {
                throw new FormatException(string.Format("{0} is not a valid index.", index));
            }

            bool leftNeightbour = IsValidIndex(array, index - 1) ? array[index] > array[index - 1] : true;
            bool rightNeightbour = IsValidIndex(array, index + 1) ? array[index] > array[index + 1] : true;

            return leftNeightbour && rightNeightbour;
        }

        static void Main()
        {
            try
            {
                int[] array = { 1, 3, 1 };
                Console.WriteLine(IsBiggerThanNeighbors(array, 1));
            }
            catch (FormatException e)
            {
                Console.Error.WriteLine(e.Message);
            }
        }
    }
}
